﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Job.Data.Interfaces;
using Job.Web.Framework;
using System.Collections;
using Job.Entity;

namespace Job.Data
{
    public class Common:BaseSqlMapDao,ICommon
    {
        #region ICommon Members

        public string GetServerTime()
        {
            try
            {
                return ExecuteQueryForObject<string>(DBObjectNames.GetServerTime, null);
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex.Message);
                return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            }
        }

        public System.Data.DataSet GetPageData(System.Data.IDataParameter[] Params)
        {
            try
            {
                return QueryForDataSetParams(DBObjectNames.GetPageData, Params);
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex.Message);
                return null;
            }
        }

        public bool Login(string username, string password)
        {
            Hashtable ht = new Hashtable();
            ht.Add("user_name", username);
            ht.Add("password", password);
            bool result = false;
            try
            {
                object obj = ExecuteQueryForObject(DBObjectNames.Login, ht);
                if (obj != null && Convert.ToInt32(obj) == 1)
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex.Message);
                return false;
            }

            return result;
        }

        public JobPersonInfo FindSinglePersonInfo(int personInfoId)
        {
            string stmtId = "Common.FindSinglePersonInfo";
            JobPersonInfo result = base.ExecuteQueryForObject<JobPersonInfo>(stmtId, personInfoId);
            return result; 
        }

        public System.Data.DataSet FetchLevelDictdata(System.Data.IDataParameter[] Params)
        {
            try
            {
                return QueryForDataSetParams(DBObjectNames.FetchLevelDictData, Params);
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex.Message);
                return null;
            }
        }

        public void UpdateCareerObjective(JobPersonInfo info)
        {
            if (info == null) throw new ArgumentNullException("info");
            string stmtId = "Common.UpdateCareerObjective";
            base.ExecuteDelete(stmtId, info);
        }

        public void UpdatePhoto(JobPersonInfo info)
        {
            if (info == null) throw new ArgumentNullException("info");
            string stmtId = "Common.UpdatePhoto";
            base.ExecuteDelete(stmtId, info);
        }

        public JobPersonInfo GetUserPhoto(int personInfoId)
        {
            string stmtId = "Common.FindUserphoto";
            JobPersonInfo result = base.ExecuteQueryForObject<JobPersonInfo>(stmtId, personInfoId);
            return result; 
        }

        public IList<ResumeList> GetResumeList(int personalAccountId)
        {
            string stmtId = "Common.FindResumeByAccountId";
            IList<ResumeList> result = base.ExecuteQueryForList<ResumeList>(stmtId, personalAccountId);
            return result; 
        }

        public void RefreshResume(int resumeId)
        {
            string stmtId = "Common.RefreshResume";
            base.ExecuteUpdate(stmtId, resumeId);
        }

        public void EditPassword(JobPersonAccount account)
        {
            string stmpId = "Common.EditPassword";
            base.ExecuteUpdate(stmpId, account);
        }
        #endregion
    }
}
